var sql = require('./sql');
var block = require('./blockChain');

module.exports = {
    'POST /signin': async (ctx, next) => {
        var
            email = ctx.request.body.email || '',
            password = ctx.request.body.password || '',
            info = await sql.login(email,password),
            eth = block.query.getInfo(info[0].account),
            denCar = await block.query.getDenCarBalance(info[0].account);
        console.log(denCar);
        if (info != -1) {
            console.log('signin ok!'+ info);
            ctx.render('signin-ok.html', {
                title: 'Sign In OK',
                name: info[0].name,
                account: info[0].account,
                eth: eth[0].balance,
                denCar: denCar,
                email: email
            });
        } else {
            console.log('signin failed!');
            ctx.render('signin-failed.html', {
                title: 'Sign In Failed'
            });
        }
    }
};


